package com.csu.mining.activity;

import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.WindowManager;
import android.widget.MediaController;
import android.widget.RelativeLayout;
import android.widget.Toast;
import android.widget.VideoView;

import com.csu.mining.R;
import com.dou361.ijkplayer.widget.PlayStateParams;
import com.dou361.ijkplayer.widget.PlayerView;

public class VideoActivity extends BaseActivity {

    private PlayerView play;
    private int order;
    private void initData() {
        Bundle mBundle = getIntent().getExtras();
        if (mBundle != null && mBundle.getSerializable("order") != null) {
            order = (int)mBundle.getSerializable("order");
            Log.e("VideoAndDocumentActivity","the order is "+ order);
        }else{
            Log.e("VideoAndDocumentActivity","the order is none");
            Toast t = Toast.makeText(this,"参数错误，即将返回", Toast.LENGTH_LONG);
            t.show();
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            onBackPressed();
        }
    }

    protected void initVideo(String title) {
        String[] videoUrls = {
                this.getString(R.string.video_url1), this.getString(R.string.video_url2),
                this.getString(R.string.video_url3), this.getString(R.string.video_url4),
                this.getString(R.string.video_url5), this.getString(R.string.video_url6),
                this.getString(R.string.video_url7), this.getString(R.string.video_url8)
        };
        String url = videoUrls[order];
        play = new PlayerView(this)
                .setTitle(title)//视频名称l);
                .setScaleType(PlayStateParams.fillparent)
                .hideMenu(true)
                .forbidTouch(false)
                .setPlaySource(url);
        play.startPlay();
    }

    @Override
    protected void onStop() {
        super.onStop();
        play.stopPlay();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        initData();
        String[] arrWays = {
                this.getString(R.string.way1),this.getString(R.string.way2),
                this.getString(R.string.way3),this.getString(R.string.way4),
                this.getString(R.string.way5),this.getString(R.string.way6),
                this.getString(R.string.way7),this.getString(R.string.way8)
        };
        initVideo(arrWays[order]);
    }
}
